<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <title>校园互助</title>
</head>

<body>
    <link href="/index.css" rel="stylesheet">
    <link rel="stylesheet" href="/main.css">
    <link rel="stylesheet" href="/weather.css">
    <script type="text/javascript" src="http://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <!--<script type="text/javascript" src="/socket.io/socket.io.js"></script>-->
    <div class="main_content">
        <header>
            <div class="user_right">
                <% if(session.user){ %>
                    <div class="has_user">
                        <a href="/adminpost">管理讨论帖</a>
                        <a href="/adminxspost">管理悬赏贴</a>
                        <a href="/adminuser">管理用户</a>
                        <span class="signout">退出</span>
                    </div>
                    <% } %>
            </div>
        </header>
        <script type="text/javascript">
            function fade(data) {
                if ($(data).css('display') !== 'none') {
                    $(data).fadeOut(1500);
                } else {
                    $(data).show();
                    $(data).fadeOut(1500);
                }
            }
            $('.signout').click(() => {
                $.ajax({
                    url: '/signout',
                    type: 'get',
                    cache: false,
                    dataType: 'json',
                    success: function(msg) {
                        if (msg) {
                            $('.success').text('退出成功');
                            fade('.success');
                            setTimeout(() => {
                                window.location.href = '/posts';
                            }, 1000);
                        }
                    },
                    error: function() {
                        alert('登出操作异常');
                    }
                });
            });
        </script>